import {$get,$post} from '@/utils/request'
import {$msg_e,$msg_s,$confirm} from '@/utils/msg'
export let list = async ()=>{
    let data = await $get('Class/List')
    console.log(data)
    return data
}
export let add = async (params)=>{
    if(!checkInput(params)){
        return false
    }
    let {success,message} = await $post('Class/Add',params)
    console.log(message)
    if(success){
        $msg_s(message)
    }else{
        $msg_e(message)
    }
    console.log(success)
    return success

}

export let update = async (params)=>{

    if(!checkInput(params)){
        return false
    }
    let {success,message} = await $post('Class/Update',params)
    if(success){
        $msg_s(message)
    }else{
        $msg_e(message)
    }
    return success
}


export let del = async (params)=>{

    await $confirm('是否确定删除')
    let {success,message} = await $post('Class/Delete',params)
    if(success){
        $msg_s(message)
    }else{
        $msg_e(message)
    }
    return success
}


let checkInput = (params)=>{

    if(!params.num){
        $msg_e('请输入班级名称')
        return false
    }else if(!params.count){
        $msg_e('请输入班级人数')
        return false
    }else if(!params.course){
        $msg_e('请输入课程名称')
        return false
    }else{
        return true
    }
}
